package com.lmm.lcbusiness.lcbusiness.pages.richtxt;

import android.widget.ImageView;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.lmm.dresswisdom.lmmframe.util.LogUtils;
import com.lmm.lcbusiness.lcbusiness.R;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * @author xmgong
 * @date 2017/5/27
 */

public class RichTxtAdapter extends BaseMultiItemQuickAdapter<RichTxtModel, BaseViewHolder> {

    public RichTxtAdapter(List<RichTxtModel> data) {
        super(data);
        addItemType(RichTxtModel.RichType_Txt, R.layout.adapter_richtxt_txt);
        addItemType(RichTxtModel.RichType_Image, R.layout.adapter_richtxt_image);
    }

    @Override
    protected void convert(final BaseViewHolder baseViewHolder, final RichTxtModel richTxtModel) {
        LogUtils.write("RichInfo:" + richTxtModel.toString());
        switch (richTxtModel.getItemType()) {
            case RichTxtModel.RichType_Txt:
                baseViewHolder.setText(R.id.tv, richTxtModel.getRichValue());
                break;
            case RichTxtModel.RichType_Image:
                Picasso.with(mContext).load(richTxtModel.getRichValue()).into((ImageView) baseViewHolder.getView(R.id.iv));
                break;
            default:
                break;
        }

        if (baseViewHolder.getPosition() == 0) {
            baseViewHolder.setGone(R.id.lin_richtxt_up, false);
        } else {
            baseViewHolder.setGone(R.id.lin_richtxt_up, true);
        }

        baseViewHolder.addOnClickListener(R.id.lin_richtxt_del);
        baseViewHolder.addOnClickListener(R.id.lin_richtxt_add);
        baseViewHolder.addOnClickListener(R.id.lin_richtxt_up);
    }
}
